#pragma once

#include <stdint.h>
#include "Buffer.h"

struct PkgBuf;
class CClient;

// 协议类型
enum class ProtType : uint8_t
{
    Invalide,
    Custom,
    WebSocket
};

struct ProtModule
{
    ProtType pt;
    int8_t iMod;
};

enum class HandleResult : int8_t
{
    Error = -1,
    Fail = 0,
    Success
};

// 数据进行协议解析
// 输入：客户端发来的原始数据
// 输出：
// 1、处理客户端发送的握手包并发回处理结果
// 2、完整的数据包，超过数据包最大长度则分包
class CProtocol
{
public:
    CProtocol();
    virtual ~CProtocol();

public:
    static CProtocol *ProtParse(CBuffer<> *pBuffer, PkgBuf *pbRecv, ProtModule &pm);
    // static CProtocol *CreateProtocol(ProtType pt);

    virtual int8_t ModuleParse(CBuffer<> *pBuffer, PkgBuf *pbRecv) = 0;
    virtual HandleResult DataParse(CBuffer<> *pBuffer, PkgBuf *pbRecv) = 0;
    virtual HandleResult DataHandle(PkgBuf *pbRecv, CClient *pClnt) = 0;

    virtual bool ProtResponse(PkgBuf *pbSend, bool bResult) = 0;
    virtual bool ModuleResponse(PkgBuf *pbSend, bool bResult) = 0;

    virtual uint16_t PackageData(uint8_t *pDest, uint8_t *pSrc, uint16_t nLen) = 0;
};
